<template>
  <div id="SettleProject" :class="{smallFontSize:showEdition,mediumFontSize:!showEdition}">
    <p style="height: 50px;display: flex;align-items: center;border-bottom: 1px solid #D2D2D2;font-size: 20px;padding: 0 10px;">
      <span style="margin-right: 10px;" class="line"></span>
      企业信息
    </p>
    <van-form show-error class="vanForm">
      <div class="inputWrap">
        <span style="color: #FF0000;">*</span>
        <van-field v-model="formData.I_compname" label="企业名称" placeholder="请输入" :rules="[{ required: true, message: '请输入企业名称' }]" />
      </div>
      <div class="inputWrap">
        <span style="color: #FF0000;">*</span>
        <van-field v-model="formData.I_tyxydm" label="统一社会信用代码" placeholder="请输入" :rules="[{ required: true, message: '请输入统一社会信用代码' }]" />
      </div>
      <div class="inputWrap">
        <span style="color: #FF0000;">*</span>
        <van-field v-model="formData.I_frxm" label="法人姓名" placeholder="请输入" />
      </div>
      <div class="inputWrap">
        <span style="color: #FF0000;">*</span>
        <van-field v-model="formData.I_frsfzh" label="法人身份证号" name="validator" placeholder="请输入" :rules="[{ validator, message: '请输入正确身份证号码' }]" />
      </div>
      <div class="inputWrap">
        <span style="color: #FF0000;">*</span>
        <van-field v-model="formData.I_frlxdh" label="法人联系电话" placeholder="请输入" :rules="[
              { required: true, message: '请填写您的联系电话！' },
              { pattern: /^1[3456789]\d{9}$/, message: '格式错误！'}
            ]" name="LXDR" />
      </div>
      <div class="inputWrap">
        <span style="color: #FF0000;">*</span>
        <van-field v-model="formData.I_dwdz" label="单位地址" placeholder="请输入" />
      </div>
      <div class="inputWrap">
        <span style="color: #FF0000;">*</span>
        <van-field v-model="formData.I_lxr" label="联系人" placeholder="请输入" :rules="[{ required: true, message: '请输入联系人' }]" />
      </div>
      <div class="inputWrap">
        <span style="color: #FF0000;">*</span>
        <van-field v-model="formData.I_lxrsfz" label="联系人身份证号" name="validator" placeholder="请输入" :rules="[{ validator, message: '请输入正确身份证号码' }]" />
      </div>
      <div class="inputWrap">
        <span style="color: #FF0000;">*</span>
        <van-field v-model="formData.I_lxdh" label="联系电话" placeholder="请输入" :rules="[
              { required: true, message: '请填写您的联系电话！' },
              { pattern: /^1[3456789]\d{9}$/, message: '格式错误！'}
            ]" name="LXDR" />
      </div>
      <p style="height: 50px;display: flex;align-items: center;border-bottom: 1px solid #D2D2D2;font-size: 20px;padding: 0 10px;">
        <span style="margin-right: 10px;" class="line"></span>
        入驻信息
      </p>
      <div class="inputWrap">
        <span style="color: #FF0000;">*</span>
        <van-field readonly clickable name="picker" :value="formData.I_fwqy | inUseName1(ENUM.FWQYARR)" label="服务区域" placeholder="请选择" @click="ENUM.FWQY = true" />
        <van-popup v-model="ENUM.FWQY" position="bottom" get-container="#popup">
          <van-picker show-toolbar :columns="ENUM.FWQYARR" value-key="CITYNAME" @confirm="confirmFWQY" @cancel="ENUM.FWQY = false" />
        </van-popup>
      </div>
      <div class="inputWrap">
        <span style="color: #FF0000;">*</span>
        <van-field readonly clickable name="picker" :value="formData.I_fwlx | inUseName(ENUM.FWLXARR)" label="服务类型" placeholder="请选择" @click="ENUM.FWLX = true" />
        <van-popup v-model="ENUM.FWLX" position="bottom" get-container="#popup">
          <van-picker show-toolbar :columns="ENUM.FWLXARR" value-key="DICNAME" @confirm="confirmFWLX" @cancel="ENUM.FWLX = false" />
        </van-popup>
      </div>
      <div class="inputWrap">
        <span style="color: #FF0000;">*</span>
        <van-field v-model="formData.I_qyrzbm" label="企业入驻编号" />
      </div>
      <div class="van-cell van-field" style="padding:10px">
        <div class="van-cell__title van-field__label">
          <span>企业介绍</span>
        </div>
      </div>
      <div class="inputWrap">
        <van-field v-model="formData.I_qyjs" rows="4" autosize label="" type="textarea" placeholder="请填写企业介绍" style="background: #E7E7E7;text-align: left;margin:10px 0" />
      </div>
    </van-form>
    <div style="height: 50px;background: #007AFF;line-height: 50px;text-align: center;color: #ffffff;font-weight: bold;" @click="BtnSaveFormData">提交申请</div>
  </div>
</template>
<script>
import { QuerySignCallback,getThirdCompanySettled, getRegister1} from '@/utils/api'
export default {
  data() {
    return {
      showEdition: true,
      formData: {
        I_COMPANYID: "",//--主键
        I_TYPE: 2,//--类型 2为inster（注册）t  3为修改（保存）
        I_rowguid: "",//--rowguid
        I_compname: "",//--公司名称
        I_tyxydm: "",//--统一信用代码
        I_frxm: "",//--法人姓名
        I_frsfzh: "",//--法人身份证号
        I_dwdz: "",//--单位地址
        I_frlxdh: "",//--法人联系电话
        I_lxr: "",//--联系人
        I_lxrsfz: "",//--联系人身份证
        I_lxdh: "",//--联系电话
        I_fwqy: "",//,--服务区域
        I_fwlx: "",//,--服务类型
        I_qyjs: "",//--企业介绍
        I_qyrzbm: "",// --企业入驻编码
      },
      ENUM: {
        FWQYARR: [],
        FWQY: false,
        FWLXARR: [],
        FWLX: false
      },
    }
  },
  filters: {
    inUseName: function (msg, data) {
      let name = ''
      data.forEach(item => {
        if (item.DICID == msg) {
          name = item.DICNAME
        }
      })
      return name
    },
    inUseName1: function (msg, data) {
      let name = ''
      data.forEach(item => {
        if (item.CITYCODE == msg) {
          name = item.CITYNAME
        }
      })
      return name
    }
  },
  methods: {
    //身份证
    validator(val) {
      var idcardReg =
        /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/
      return idcardReg.test(val)
    },
    handleConfirm(value) { },
    getCityOpenDataView: async function () {
      this.CityColumns = []
      let dataGuid = 'e9c98787-4966-4365-80b0-c1cc678c6f85'
      let token = window.localStorage.getItem('token')
      let params = {
        accessCode: "688bd3883572440a859dfd8ba9194e7b",

        params: {
          dataguid: dataGuid,
          searchObject: JSON.stringify([]),
          token: token,
        },
      };
      const res = await QuerySignCallback(params);
      this.ENUM.FWQYARR = JSON.parse(res.data.data).Data
    },
    //提交申请
    BtnSaveFormData: async function () {
      // 判断必填项是否填写
      if (this.formData.I_compname && this.formData.I_tyxydm && this.formData.I_frxm && this.formData.I_frsfzh && this.formData.I_dwdz && this.formData.I_frlxdh && this.formData.I_lxr && this.formData.I_lxrsfz && this.formData.I_lxdh && this.formData.I_fwqy && this.formData.I_fwlx && this.formData.I_qyrzbm) {
        //将信息保存到业务系统
        let paerauto = {
          procName: 'up_company',
          dtParams: JSON.stringify([this.formData]),
          token: window.localStorage.getItem('token')
        }
        let procNameAuto = {
          accessCode: "69db6bece3a7480592e2ec753d1e335e",

          cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
          params: paerauto
        }
        const res = await QuerySignCallback(procNameAuto);
        if (res.data.code == 200) {
          //将企业用户信息注册在业务系统
           var type = ""
           if(this.formData.I_fwlx == '446'){
             type = '8'
           }else if(this.formData.I_fwlx == '447'){
             type = '99'
           } else {
             type = '41'
           }
           let pae = {
            loginName: this.formData.I_tyxydm, //用户
            sfzh: this.formData.I_frsfzh, //村citycode
            mobile: this.formData.I_frlxdh, //身份证号
            roleNode:type,
            qyid: this.formData.I_tyxydm,
            st_name:this.formData.I_compname,
            zjcitycode:this.formData.I_fwqy,
            citycode:this.formData.I_fwqy,
            token: window.localStorage.getItem('token')
          }
          let p = {
              accessCode: "2134a39b52f6437ca2590530d2142b3a",

              cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
              params: pae
          }
          const data1 = await QuerySignCallback(p)
          //同时将信息保存到统一支撑平台
          let params = {
            accessCode: "69db6bece3a7480592e2ec753d1e335e",

            cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
            dwdz  : this.formData.I_dwdz,
            frdh  : this.formData.I_frlxdh,
            frxm  : this.formData.I_frxm,
            fwlx  : this.formData.I_fwlx,
            lxr   : this.formData.I_lxr,
            zzjgdm : this.formData.I_tyxydm,
          }
          const res = await getThirdCompanySettled(params)
          this.$toast.success(res.data.msg);
        } else {
          this.$toast.fail(res.data.msg);
        }
      } else {
        this.$toast.fail('请输入必选项！');
      }

    },
    //服务区域下拉选择
    confirmFWQY(val) {
      this.formData.I_fwqy = val.CITYCODE
      this.ENUM.FWQY = false
    },
    //服务类型下拉选择
    confirmFWLX(val) {
      this.formData.I_fwlx = val.DICID
      this.ENUM.FWLX = false
    },
    getData: async function (type) {
      //-类型 1为查询企业信息；2为查询服务类型字典
      let formData = JSON.parse(window.localStorage.getItem('FRUSER'))
      let arr = [{ I_TYPE: type }]
      if (type == 1) {
        arr = [{ I_TYXYDM: "'" + formData.uniscid + "'" }]
      }
      let paerauto = {
        procName: type === 1 ? 'up_companyFwlx' : 'up_companyselect',
        dtParams: JSON.stringify(arr),
        token: window.localStorage.getItem('token')
      }
      let procNameAuto = {
        accessCode: '69db6bece3a7480592e2ec753d1e335e',

        cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
        params: paerauto
      }
      const res = await QuerySignCallback(procNameAuto)
      let data = eval('(' + res.data.data + ')').Data
      if (type == 2) {
        this.ENUM.FWLXARR = data
      } else if (type == 1) {
        if (data.length > 0) {
          this.formData = {
            I_COMPANYID: data[0].PKID,//--主键
            I_TYPE: 3,//--类型 2为inster（注册）t  3为修改（保存）
            I_rowguid: data[0].ROW_GUID,//--rowguid
            I_compname: data[0].COMAPNY_NAME,//--公司名称
            I_tyxydm: data[0].TYSHXYDM,//--统一信用代码
            I_frxm: data[0].FRXM,//--法人姓名
            I_frsfzh: data[0].FRSFZH,//--法人身份证号
            I_dwdz: data[0].DWDZ,//--单位地址
            I_frlxdh: data[0].FRLXDH,//--法人联系电话
            I_lxr: data[0].LXR,//--联系人
            I_lxrsfz: data[0].LXRSFZ,//--联系人身份证
            I_lxdh: data[0].LXDH,//--联系电话
            I_fwqy: Number(data[0].FWQY),//,--服务区域
            I_fwlx: data[0].FWLX,//,--服务类型
            I_qyjs: data[0].QYJS,//--企业介绍
            I_qyrzbm: data[0].QYRZBM,// --企业入驻编码
          }
        } else {
          this.formData.I_compname = formData.CompanyName;
          this.formData.I_tyxydm = formData.uniscid;
          this.formData.I_frxm = formData.attnName;
          this.formData.I_frlxdh = formData.attnPhone;
          this.formData.I_frsfzh = formData.attnIDNo;
          //   this.formData.I_qyrzbm = formData.CompanyRegNumber;
        }
      }
    }
  },
  mounted() {
    this.showEdition = this.$store.state.Edition;
    this.getData(1)
    this.getData(2)
    this.getCityOpenDataView()
    if (ZWJSBridge) {
      ZWJSBridge.setTitle({
        "title": "企业入驻"
      }).then(res => {
      }).catch(err => {
      })
    }
  },
}
</script>
<style lang="scss">
#SettleProject {
  height: 100vh;
  overflow: auto;
  .van-cell:not(:last-child)::after {
    left: 0;
    // border-bottom: 1px solid rgb(210, 210, 210);
  }
  .van-cell {
    padding: 10px 0;
    font-size: 16px;
  }
  .van-field__control {
    text-align: right;
  }
  .van-field__label {
    color: black !important;
    letter-spacing: 1px;
  }
  .van-cell {
    color: black;
  }
  .line {
    width: 6px;
    height: 26px;
    background: #007aff;
    display: inline-block;
  }
  .inputWrap {
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid #d2d2d2;
    padding: 0 10px;
    min-height: 40px;
    line-height: 40px;
    justify-content: space-between;
  }
  .vanForm {
    width: 100%;
    height: calc(100vh - 100px);
    overflow: auto;
    display: block;
  }
  textarea {
    text-align: left !important;
  }
}
</style>
